package autoTest.request;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import autoTest.command.Params;
import main.ServerMain;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

public class QuerryPart extends RequestPart {
	private static final long serialVersionUID = 2271797150647771296L;
	public QuerryPart() {}

	@Override public void process(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { 
		resp.setCharacterEncoding("UTF-8");  
		resp.setContentType("text/plain");
		resp.setStatus(HttpServletResponse.SC_OK);
		PrintWriter pWriter = resp.getWriter();
		JSONObject joRet = new JSONObject();		//存储返回消息
		JSONArray joDeviceList = new JSONArray();		//存储设备信息
		for (String deviceId : ServerMain.allDeviceInfo.keySet()) {
			JSONObject jo = new JSONObject();
			jo.put(Params.PLAT_FORM, ServerMain.allDeviceInfo.get(deviceId).getPlatform());
			jo.put(Params.DEVICE_ID, deviceId);
			jo.put(Params.STATUS, ServerMain.allDeviceInfo.get(deviceId).getStatus());
			joDeviceList.add(jo);
		}
		joRet.put(Params.CODE, 0);
		joRet.put(Params.DEVICE_INFO_LIST, joDeviceList);
		pWriter.println(joRet.toString());  
	}
}
